package com.yunform.framework.hibernate;

import java.util.List;



public class DBUtil {
	
	public static String genRowId(){
		return ObjectId.get();
	}
	
	public static String prepareSelectSQL(String tabId,List<String> colIds ) {
		StringBuffer sb = new StringBuffer();
		sb.append("select ");
		sb.append("ID" );
		for(String colId : colIds){
			sb.append("," + colId);
		}
		sb.append(" from " + tabId);
		
		return sb.toString() ;
	}
	
	
	public static String prepareUpdateByRowIdSQL(String formId, List<String> colIds) {
		StringBuffer sb = new StringBuffer();
		sb.append("update " + formId +" set " );
		String colId = colIds.get(0);
		sb.append("" + colId +" = :" + colId);
		for(int i=1;i<colIds.size(); i++){
			colId = colIds.get(i);
			sb.append("," + colId +" = :" + colId);
		}
		sb.append(" where ID = :ID " );
		
		return sb.toString();
	}
	
	public static String prepareDeleteByRowIdSQL(String formId) {
		StringBuffer sb = new StringBuffer();
		sb.append("delete from  " + formId );
		sb.append(" where ID = :ID " );
		
		return sb.toString();
	}
	
	
}
